﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.UnifyShow.Business;
using Microsoft.Practices.Unity;
using System.Windows.Forms.DataVisualization.Charting;
using System.Threading;
using System.IO;
using Oracle.DataAccess.Client;
using System.Drawing;
using Wicresoft.UnifyShow.Portal.Extensions;

namespace Wicresoft.UnifyShow.Portal.Controllers
{
    public class IncidentController : BaseController
    {
        // 声明变量
        private IIncident incident;
        private DateTime sTimes;
        private DateTime eTimes;
        Chart chart1 = new Chart();
        Series series1 = new Series();
        Series series2 = new Series();
        ChartArea chartArea1 = new ChartArea();
        //时间转换和为空处理
        private void timeSet(string sTime, string eTime)
        {
            sTimes = Convert.ToDateTime(sTime);
            eTimes = Convert.ToDateTime(eTime);
            if (sTime == null)
                sTimes = GlobalHelper.starTime;
            if (eTime == null)
                eTimes = GlobalHelper.endTime;
        }
        protected override void Dispose(bool disposing)
        {
            ((IDisposable)incident).Dispose();
        }

        [InjectionConstructor]
        public IncidentController(IIncident e)
        {
            incident = e;
        }

        //事件成功关闭的数量/百分比(饼图)
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentApproveCount(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //地市事件总数量
            Decimal imAll = incident.GetCountIncident(sid, bnid, sTimes, eTimes);
            //地市事件已解决数量
            Decimal imApp = incident.GetApproveCountIncident(sid, bnid, sTimes, eTimes);
            //获取地市事件未解决数百分比
            double NotAppNum = ((double)imAll - (double)imApp) / (double)imAll;
            //获取地市事件已解决数百分比
            double ApproveNum = (double)imApp / (double)imAll;
            NotAppNum = Convert.ToDouble(NotAppNum);
            ApproveNum = Convert.ToDouble(ApproveNum);
            //Series
            series1.ChartType = SeriesChartType.Pie;
            double[] yval = { ApproveNum, NotAppNum };
            string[] xval = { (ApproveNum * 100).ToString("0.00") + "%", (NotAppNum * 100).ToString("0.00") + "%" };
            series1.Points.DataBindXY(xval, yval);
            //添加图列
            Legend x = new Legend();
            x.BorderColor = Color.Black;
            chart1.Legends.Add(x);
            series1.Points[0].LegendText = "已关闭";
            series1.Points[1].LegendText = "未关闭";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            //ChartArea
            chartArea1.Name = "Default";
            chartArea1.AxisY.LabelStyle.Format = "0%";
            //Chart
            chart1.Width = GlobalHelper.Width;
            chart1.Height = GlobalHelper.Height;
            //Title t = new Title("事件解决率");
            //t.Font = GlobalHelper.fontTitle;
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart1.PaletteCustomColors = colorSet;
            //chart1.Titles.Add(t);
            chart1.Series.Add(series1);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //事件总数（柱状图）
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentCount(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //数据处理
            DateTime date1 = DateTime.Parse(sTimes.ToString().Trim());
            int year1 = Convert.ToInt16(date1.ToString("yyyy"));
            int month1 = Convert.ToInt16(date1.ToString("MM"));
            int day1 = Convert.ToInt16(date1.ToString("dd"));
            DateTime date2 = DateTime.Parse(eTimes.ToString().Trim());
            int year2 = Convert.ToInt16(date2.ToString("yyyy"));
            int month2 = Convert.ToInt16(date2.ToString("MM"));
            int day2 = Convert.ToInt16(date2.ToString("dd"));

            List<IncidentAndChangeModel> ims = incident.GetIncidentList(sid, bnid, sTimes, eTimes);
            //Series
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                var item1 = ims.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), item1.alls.ToString("0.00"));
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }
            //设置Y轴刻度间隔
            double max = 0;
            double min = 0;
            if (series1.Points.Count != 0)
            {
                max = Math.Floor(series1.Points.FindMaxByValue().YValues[0] * 1.1);
                min = Math.Floor(series1.Points.FindMinByValue().YValues[0] * 0.9);
            }
            double differ = (max - min) / 10.0;
            int intervalY = (int)Math.Floor(differ) + 1;
            chartArea1.AxisY.Maximum = max;
            chartArea1.AxisY.Minimum = min;
            chartArea1.AxisY.Interval = intervalY;
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            series1.IsValueShownAsLabel = true;
            series1.XValueType = ChartValueType.String;
            ////设置宽度
            series1["PointWidth"] = "0.6";
            //柱状图样式设计
            series1["DrawingStyle"] = "Emboss";
            series1.Name = "个数";
            series1.ChartType = SeriesChartType.Column;
            series1.IsValueShownAsLabel = true;
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            //ChartArea
            //设置墙的宽度为
            //chartArea1.Area3DStyle.WallWidth = 30;
            //不显示网格线
            chartArea1.AxisX.MajorGrid.Enabled = chartArea1.AxisY.MajorGrid.Enabled = false;
            //设置X轴刻度间隔
            //chartArea1.AxisY.Interval = 20;
            chartArea1.AxisX.Interval = 1;
            //Chart
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.OneSet;
            chart1.PaletteCustomColors = colorSet;
            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            chart1.Legends.Add(x);
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("事件总数");
            //t.Font = GlobalHelper.fontTitle;
            //chart1.Titles.Add(t);

            chart1.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            chart1.Series.Add(series1);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //按照事件结束代码分类(饼图)
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentCloseCode(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            List<IncidentAndChangeModel> icm = incident.GetIncidentCloseCodeBysite(sid, bnid, sTimes, eTimes);
            if (icm.FirstOrDefault(p => p.ID == 19000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 19000 });
            }
            if (icm.FirstOrDefault(p => p.ID == 15000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 15000 });
            }
            if (icm.FirstOrDefault(p => p.ID == 16000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 16000 });
            }
            if (icm.FirstOrDefault(p => p.ID == 11000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 11000 });
            }
            if (icm.FirstOrDefault(p => p.ID == 14000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 14000 });
            }
            if (icm.FirstOrDefault(p => p.ID == 17000) == null)
            {
                icm.Add(new IncidentAndChangeModel { alls = 0, ID = 17000 });
            }
            List<double> lyval = new List<double>();
            List<string> lxval = new List<string>();
            List<string> llegend = new List<string>();
            double sum = (double)icm.Sum(p => p.alls);
            foreach (var ResultSort in icm)
            {
                double percent = (double)ResultSort.alls / sum;
                lyval.Add(percent);
                lxval.Add((percent * 100).ToString("0.00") + "%");
                switch (ResultSort.ID.ToString())
                {
                    case "19000": llegend.Add("根本解决");
                        break;
                    case "15000": llegend.Add("不成功解决");
                        break;
                    case "16000": llegend.Add("变通方法解决");
                        break;
                    case "11000": llegend.Add("消失");
                        break;
                    case "14000": llegend.Add("误报");
                        break;
                    case "17000": llegend.Add("用户误操作");
                        break;
                }
            }
            //Series
            double[] yval = lyval.ToArray();
            string[] xval = lxval.ToArray();
            string[] legend = llegend.ToArray();
            series1.ChartType = SeriesChartType.Pie;
            series1.Points.DataBindXY(xval, yval);
            for (int i = 0; i < legend.Length; i++)
            {
                series1.Points[i].LegendText = legend[i];
            }
            // 设置标签风格
            //series1["PieLabelStyle"] = "Outside";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            //ChartArea
            //chartArea1.AxisY.LabelStyle.Format = "0%";
            //Chart
            chart1.Width = GlobalHelper.Width;
            chart1.Height = GlobalHelper.Height;
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.SixColorSet;
            chart1.PaletteCustomColors = colorSet;
            Legend x = new Legend();
            x.BorderColor = Color.Black;
            chart1.Legends.Add(x);
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //Title t = new Title("事件原因分析");
            //t.Font = GlobalHelper.fontTitle;
            //chart1.Titles.Add(t);
            chart1.Series.Add(series1);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //平均解决时间（柱状图）
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentAvgTime(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //数据处理
            DateTime date1 = DateTime.Parse(sTimes.ToString().Trim());
            int year1 = Convert.ToInt16(date1.ToString("yyyy"));
            int month1 = Convert.ToInt16(date1.ToString("MM"));
            int day1 = Convert.ToInt16(date1.ToString("dd"));
            DateTime date2 = DateTime.Parse(eTimes.ToString().Trim());
            int year2 = Convert.ToInt16(date2.ToString("yyyy"));
            int month2 = Convert.ToInt16(date2.ToString("MM"));
            int day2 = Convert.ToInt16(date2.ToString("dd"));
            //取数据
            List<IncidentAndChangeModel> ims = incident.GetCountIncidentAvgtmeBySite(sid, bnid, sTimes, eTimes);
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                var item1 = ims.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), item1.alls.ToString("0.00"));
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }
            //设置Y轴刻度间隔
            double max = 0;
            double min = 0;
            if (series1.Points.Count != 0)
            {
                max = series1.Points.FindMaxByValue().YValues[0] * 1.5;
                min = series1.Points.FindMinByValue().YValues[0] * 1.2;
            }
            double differ = (max - min) / 10.0;
            int intervalY = (int)Math.Floor(differ);
            double intervalY2 = (double)differ + 1;
            chartArea1.AxisY.Maximum = max;
            chartArea1.AxisY.Minimum = min;
            chartArea1.AxisY.Interval = intervalY;
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            series1.BorderColor = System.Drawing.Color.FromArgb(180, 26, 59, 105);
            series1.IsValueShownAsLabel = true;
            series1.XValueType = ChartValueType.String;
            ////设置宽度
            series1["PointWidth"] = "0.6";
            series1.Name = "小时";
            series1.ChartType = SeriesChartType.Column;
            //ChartArea
            //设置墙的宽度为
            chartArea1.Area3DStyle.WallWidth = 2;
            //设置XY轴刻度间隔
            chartArea1.AxisX.Interval = 1;
            //柱状图样式设计
            series1["DrawingStyle"] = "Emboss";
            //不显示网格线
            chartArea1.AxisX.MajorGrid.Enabled = chartArea1.AxisY.MajorGrid.Enabled = false;
            //Chart
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.OneSet;
            chart1.PaletteCustomColors = colorSet;
            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            chart1.Legends.Add(x);
            //设置图标题（上方显示）
            //Title t = new Title("平均解决时间");
            //t.Font = GlobalHelper.fontTitle;
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //chart1.Titles.Add(t);
            chart1.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            chart1.Series.Add(series1);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //事件升级率 (饼图)
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentEscalation(int? sid, int? bnid, string sTime, string eTime)
        {
            int returns = GlobalHelper.Escalations(sid);
            if (returns == 0)
            {
                return new ChartResult(chart1);
            }
            else
            {
                //时间转换和为空处理
                timeSet(sTime, eTime);
                Decimal escalationcount = incident.GetIncidentEscalationBySite(sid, bnid, sTimes, eTimes);
                Decimal allchCount = incident.GetCountIncident(sid, bnid, sTimes, eTimes);

                double chEscalation = (double)escalationcount / (double)allchCount;
                double chOther = 1 - chEscalation;
                double[] yval = { chEscalation, chOther };
                string[] xval = { (chEscalation * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };
                //Series
                series1.ChartType = SeriesChartType.Pie;
                series1.Points.DataBindXY(xval, yval);
                series1.Points[0].LegendText = "升级事件 ";
                series1.Points[1].LegendText = "未升级事件 ";
                //图样式 concave/SoftEdge
                series1["PieDrawingStyle"] = "SoftEdge";
                //ChartArea
                chartArea1.AxisY.LabelStyle.Format = "0%";
                //Chart
                Legend x = new Legend();
                x.BorderColor = Color.Black;
                chart1.Legends.Add(x);
                chart1.Width = GlobalHelper.Width;
                chart1.Height = GlobalHelper.Height;
                //设置图列样式颜色
                chart1.Legends[0].Font = GlobalHelper.fontLegend;
                //此属性设置为None才可以自定义调色板
                chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
                // 自定义调色板
                Color[] colorSet = GlobalHelper.TwoSetPei;
                chart1.PaletteCustomColors = colorSet;
                //Title t = new Title("事件升级率");
                //t.Font = GlobalHelper.fontTitle;
                //chart1.Titles.Add(t);
                chart1.Series.Add(series1);
                chart1.ChartAreas.Add(chartArea1);
                return new ChartResult(chart1);
            }

        }

        //重大事件数量/百分比（柱状图）
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentImpact(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //数据处理
            DateTime date1 = DateTime.Parse(sTimes.ToString().Trim());
            int year1 = Convert.ToInt16(date1.ToString("yyyy"));
            int month1 = Convert.ToInt16(date1.ToString("MM"));
            int day1 = Convert.ToInt16(date1.ToString("dd"));
            DateTime date2 = DateTime.Parse(eTimes.ToString().Trim());
            int year2 = Convert.ToInt16(date2.ToString("yyyy"));
            int month2 = Convert.ToInt16(date2.ToString("MM"));
            int day2 = Convert.ToInt16(date2.ToString("dd"));
            //一般事件
            List<IncidentAndChangeModel> ims2 = incident.GetSeriousCountIncidentByImpact(sid, bnid, sTimes, eTimes);
            //重大事件
            List<IncidentAndChangeModel> ims1 = incident.GetGeneralCountIncidentByImpact(sid, bnid, sTimes, eTimes);
            //Series
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                //严重
                var item1 = ims1.Where(p => p.sign == mo).FirstOrDefault();
                //一般
                var item2 = ims2.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    if (item2 != null)
                    {
                        //百分比
                        Decimal g1 = Convert.ToDecimal(item1.alls / (item1.alls + item2.alls));
                        series1.Points.AddXY(mo.Substring(mo.Length - 2), g1.ToString("0.00"));
                    }
                    else
                    {
                        series1.Points.AddXY(mo.Substring(mo.Length - 2), 1);
                    }
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
                if (item2 != null)
                {
                    if (item1 != null)
                    {
                        //百分比
                        Decimal g2 = Convert.ToDecimal(item2.alls / (item1.alls + item2.alls));
                        series2.Points.AddXY(mo.Substring(mo.Length - 2), g2.ToString("0.00"));
                    }
                    else
                    {
                        series2.Points.AddXY(mo.Substring(mo.Length - 2), 1);
                    }
                }
                else
                {
                    series2.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            //设置宽度
            series1["PointWidth"] = "0.5";
            series2["PointWidth"] = "0.5";
            series2.Name = "严重";
            series1.Name = "一般";
            series1.LabelFormat = "0%";
            series2.LabelFormat = "0%";
            series1.ChartType = SeriesChartType.StackedColumn;
            series2.ChartType = SeriesChartType.StackedColumn;
            series1.IsValueShownAsLabel = true;
            series2.IsValueShownAsLabel = true;
            //ChartArea
            //设置XY轴刻度间隔
            chartArea1.AxisY.Interval = 0.2;
            chartArea1.AxisX.Interval = 1;
            //设置XY轴最大值
            chartArea1.AxisY.Maximum = 1;
            //chartArea1.AxisX.Maximum = 12;
            //设置墙的宽度为
            chartArea1.Area3DStyle.WallWidth = 2;
            //设置背景为白色
            chartArea1.BackColor = Color.White;
            chartArea1.Name = "Default";
            chartArea1.AxisY.LabelStyle.Format = "0%";
            //设置图标题（下方显示）
            //chartArea1.AxisX.Title = "事件影响程度";
            //是否3D显示
            chartArea1.Area3DStyle.Enable3D = true;
            //Chart
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetBar;
            chart1.PaletteCustomColors = colorSet;
            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            //x.Title = "影响程度";
            chart1.Legends.Add(x);
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("事件影响程度");
            //t.Font = GlobalHelper.fontTitle;
            //chart1.Titles.Add(t);
            chart1.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            chart1.Series.Add(series1);
            chart1.Series.Add(series2);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //规定时间内解决的事件数量/百分比(饼图)
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentResolvedTimeOut(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //地市事件已解决总数量
            Decimal imAll = incident.GetApproveCountIncident(sid, bnid, sTimes, eTimes);
            //规定时间内解决的事件数量(未超时) GetCountIncidentByResolvedTimeOut
            Decimal imNot = incident.GetCountIncidentByResolvedTimeOut(sid, bnid, sTimes, eTimes);
            //获取地市事件规定时间内未解决数百分比 （超时）
            double TimeOut = ((double)imAll - (double)imNot) / (double)imAll;
            //获取地市事件已解决数百分比 （未超时）
            double NotTimeOut = (double)imNot / (double)imAll;
            TimeOut = Convert.ToDouble(TimeOut);
            NotTimeOut = Convert.ToDouble(NotTimeOut);
            series1.ChartType = SeriesChartType.Pie;
            //Series
            double[] yval = { NotTimeOut, TimeOut };
            string[] xval = { (NotTimeOut * 100).ToString("0.00") + "%", (TimeOut * 100).ToString("0.00") + "%" };
            series1.Points.DataBindXY(xval, yval);
            //分割饼图
            //series1.Points[0]["Exploded"] = "true";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            series1.Points[1].LegendText = "超时事件";
            series1.Points[0].LegendText = "未超时事件";
            //ChartArea
            chartArea1.Name = "Default";
            chartArea1.AxisY.LabelStyle.Format = "0%";
            //Chart
            //设置颜色
            //chart1.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart1.PaletteCustomColors = colorSet;
            //添加图列
            Legend x = new Legend();
            x.BorderColor = Color.Black;
            chart1.Legends.Add(x);
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            chart1.Width = GlobalHelper.Width;
            chart1.Height = GlobalHelper.Height;
            //Title t = new Title("规定时间内解决的事件");
            //t.Font = GlobalHelper.fontTitle;
            //chart1.Titles.Add(t);
            chart1.Series.Add(series1);
            chart1.ChartAreas.Add(chartArea1);
            return new ChartResult(chart1);
        }

        //一线解决率（服务台+现场工程师）、二线解决率（柱状图）
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult IncidentResolvedGroup(int? sid, int? bnid, string sTime, string eTime)
        {
            //时间转换和为空处理
            timeSet(sTime, eTime);
            //数据处理
            DateTime date1 = DateTime.Parse(sTimes.ToString().Trim());
            int year1 = Convert.ToInt16(date1.ToString("yyyy"));
            int month1 = Convert.ToInt16(date1.ToString("MM"));
            int day1 = Convert.ToInt16(date1.ToString("dd"));
            DateTime date2 = DateTime.Parse(eTimes.ToString().Trim());
            int year2 = Convert.ToInt16(date2.ToString("yyyy"));
            int month2 = Convert.ToInt16(date2.ToString("MM"));
            int day2 = Convert.ToInt16(date2.ToString("dd"));
            //一线解决率
            List<IncidentAndChangeModel> ims1 = incident.GetCountIncidentByResolvedGroup1(sid, bnid, sTimes, eTimes);
            //二线解决率
            List<IncidentAndChangeModel> ims2 = incident.GetCountIncidentByResolvedGroup2(sid, bnid, sTimes, eTimes);
            //Series
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                //一线
                var item1 = ims1.Where(p => p.sign == mo).FirstOrDefault();
                //二线
                var item2 = ims2.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    if (item2 != null)
                    {
                        //百分比
                        Decimal g1 = Convert.ToDecimal(item1.alls / (item1.alls + item2.alls));
                        series1.Points.AddXY(mo.Substring(mo.Length - 2), g1.ToString("0.00"));
                    }
                    else
                    {
                        series1.Points.AddXY(mo.Substring(mo.Length - 2), 1);
                    }
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
                if (item2 != null)
                {
                    if (item1 != null)
                    {
                        //百分比
                        Decimal g2 = Convert.ToDecimal(item2.alls / (item1.alls + item2.alls));
                        series2.Points.AddXY(mo.Substring(mo.Length - 2), g2.ToString("0.00"));
                    }
                    else
                    {
                        series2.Points.AddXY(mo.Substring(mo.Length - 2), 1);
                    }
                }
                else
                {
                    series2.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            //图样式 concave/SoftEdge
            series1["PieDrawingStyle"] = "SoftEdge";
            //设置宽度
            series1["PointWidth"] = "0.5";
            series2["PointWidth"] = "0.5";
            //series1.BorderColor = System.Drawing.Color.FromArgb(189, 26, 59, 115);
            //series1.ChartArea = "Default";
            //series1.Legend = "Default";
            series1.Name = "一线";
            series2.Name = "二线";
            //series1.XValueType = ChartValueType.String;
            series1.LabelFormat = "0%";
            series2.LabelFormat = "0%";
            series1.ChartType = SeriesChartType.StackedColumn;
            series2.ChartType = SeriesChartType.StackedColumn;
            series1.IsValueShownAsLabel = true;
            series2.IsValueShownAsLabel = true;
            //ChartArea
            //设置XY轴刻度间隔
            chartArea1.AxisY.Interval = 0.2;
            chartArea1.AxisX.Interval = 1;
            //设置XY轴最大值
            chartArea1.AxisY.Maximum = 1;
            //chartArea1.AxisX.Maximum = 12;
            //设置墙的宽度为
            chartArea1.Area3DStyle.WallWidth = 2;
            //设置背景为白色
            chartArea1.BackColor = Color.White;
            chartArea1.Name = "Default";
            chartArea1.AxisY.LabelStyle.Format = "0%";
            //设置图标题（下方显示）
            //chartArea1.AxisX.Title = "一二线解决率";
            //是否3D显示
            chartArea1.Area3DStyle.Enable3D = true;
            //Chart
            //设置柱状颜色
            //colChart.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetBar;
            chart1.PaletteCustomColors = colorSet;

            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            //x.Title = "解决率";
            chart1.Legends.Add(x);
            //设置图列样式颜色
            chart1.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("一二线解决率");
            //t.Font = GlobalHelper.fontTitle;
            //chart1.Titles.Add(t);
            chart1.Series.Add(series1);
            chart1.Series.Add(series2);
            chart1.ChartAreas.Add(chartArea1);
            chart1.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            return new ChartResult(chart1);
        }
    }
}
